import request from '@/utils/request';
import type {
  BaseBeanModel,
  ResponseBaseData,
  ResponsePageData,
  QueryParamModel,
  TreeNodeModel
} from '@/api/model/baseModel';

const basePath = '/appsys/datapermissions/';

/** 数据权限分配 */
export interface SysDataPermissionsAuthDto extends BaseBeanModel {
  /** 角色ID */
  roleId?: string;
  /** 方法ID */
  methodId?: string;
  /** 规则ID串 */
  ruleIds?: string;
  /** 公式 */
  formula?: string;
  /** 过滤条件 */
  filterCondition?: string;
  /** 过滤条件sql */
  filterConditionsql?: string;
  /** ATTRIBUTE_01 */
  attribute01?: string;
  /** ATTRIBUTE_02 */
  attribute02?: string;
  /** ATTRIBUTE_03 */
  attribute03?: string;
  /** ATTRIBUTE_04 */
  attribute04?: string;
  /** ATTRIBUTE_05 */
  attribute05?: string;
  /** ATTRIBUTE_06 */
  attribute06?: string;
  /** ATTRIBUTE_07 */
  attribute07?: string;
  /** ATTRIBUTE_08 */
  attribute08?: string;
  /** ATTRIBUTE_09 */
  attribute09?: string;
  /** ATTRIBUTE_10 */
  attribute10?: string;
  /** SYS_APPLICATION_ID */
  sysApplicationId?: string;
}

/**
 * 获取分页数据
 * @param param 表格参数
 * @returns 表格数据
 */
export function listSysDataPermissionsAuthByPage(
  param: QueryParamModel
): Promise<ResponsePageData<SysDataPermissionsAuthDto>> {
  return request.post('/appsys/role/RoleRest/searchByPage/v1', param);
}

/**
 * 获取菜单树
 * @param param { pid }
 * @param level 层级
 * @param menuType 菜单类型
 * @returns 菜单树数据
 */
export function getMenuTree(param: object, level: number, menuType: string): Promise<ResponseBaseData<TreeNodeModel>> {
  return request.post(`${basePath}SysDataPermissionsAuthRest/vuemenumethod/${level}/${menuType}`, param);
}

/**
 * 搜索树数据
 * @param param { searchText 搜索的值 }
 * @param menuType 菜单类型
 * @returns 菜单树数据
 */
export function searchTreeList(param: object, menuType: string): Promise<ResponseBaseData<TreeNodeModel>> {
  return request.post(`${basePath}SysDataPermissionsAuthRest/vuemenumethod/search/${menuType}/v1`, param);
}

/**
 * 根据id加载授权数据
 * @param roleId 角色id
 * @param menuId 菜单id
 * @returns 规则授权详情
 */
export function getSysDataPermissionsAuth(roleId: string, menuId: string): Promise<ResponseBaseData<any>> {
  return request.get(
    `${basePath}SysDataPermissionsAuthRest/querySysDataPermissionsAuthByRoleAndMethod/v1/${roleId}/${menuId}`
  );
}

/**
 * 保存表单数据
 * @param form 表单数据
 */
export function saveSysDataPermissionsAuth(form: SysDataPermissionsAuthDto): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}SysDataPermissionsAuthRest/save/v1`, form);
}

/**
 * 根据id加载规则授权详情数据
 * @param id 规则id
 * @returns 规则详情数据
 */
export function getSysDataPermissionsAuthDetail(id: string): Promise<ResponseBaseData<any>> {
  return request.get(`${basePath}SysDataPermissionsMethodRest/getSub/v1/${id}`);
}
